package busi

import (
	"errors"
	"fmt"
	"gitee.com/youbeiwuhuan/gin-practice/go-err/errs"
)

// BusinessErr / 根业务错误
type BusinessErr struct {
	msg string
}

func (e *BusinessErr) Error() string {
	return e.msg
}

// Code  错误编码
func (e *BusinessErr) Code() string {
	return ""
}

// Data 附带数据
func (e *BusinessErr) Data() interface{} {
	return nil
}

// UserNotFoundErr / 用户未找到错误
type UserNotFoundErr struct {
	*BusinessErr
}

func (e *UserNotFoundErr) Error() string {
	return e.msg
}

func IsBaseError() {
	be := &BusinessErr{
		msg: "BusinessErr",
	}

	fmt.Println(errors.Is(be, &BusinessErr{}))

	if _, ok := interface{}(be).(errs.BaseError); ok {
		fmt.Println("BusinessErr 实现了 BaseError 接口")
	} else {
		fmt.Println("BusinessErr 没有实现 BaseError 接口")
	}

	ue := &UserNotFoundErr{}
	if _, ok := interface{}(ue).(errs.BaseError); ok {
		fmt.Println("UserNotFoundErr 实现了 BaseError 接口")
	} else {
		fmt.Println("UserNotFoundErr 没有实现 BaseError 接口")
	}
}
